<?php 
namespace app\Home\controller;
use think\Controller;
use think\Request;
use think\Db;
class Register extends Controller
{
	public function register(){
		return $this->fetch();
	}

	//注册入库
	public function regist_do(){
	   $data = Request::instance()->post();
       $data['password'] = md5($data['password']);
       // print_r($data['password']);die; 
	   $res  = Db::name('login')->insert($data);
	   if ($res){
	            $this->redirect('Home/login/login');
	        }else{
	            echo "<script>alert('注册失败');location.href='Home/Regist/regist'</script>";
	        }
	    }

    //注册验证用户名唯一性
    public function regist_once()
    {
        $username=Request::instance()->post("username");
        // var_dump($username);die;
     	$res=Db::table("login")->where("username='$username'")->select();
        // var_dump($res);die;
        if($res){
            return 2;
        }else{
            return 3;
        }
    }

    //注册验证手机号唯一性
    public function regist_once_tell()
    {
        $tell=Request::instance()->post("tell");
        // var_dump($tell);die;
        $res=Db::table("login")->where("tell='$tell'")->select();
        // var_dump($res);die;
        if ($res) {
            return 2;
        }else{
            return 3;
        }
    }

    //注册验证邮箱唯一性
    public function regist_once_email()
    {
        $email=Request::instance()->post("email");
        // var_dump($email);die;
        $res=Db::table("login")->where("email='$email'")->select();
        // var_dump($res);die;
        if ($res) {
            return 2;
        }else{
            return 3;
        }
    }



}